package qldc.pm.tiensu.service.persistence;

import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnmodifiableList;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException;
import qldc.pm.tiensu.model.TEMP_DoiTuongTienSu;
import qldc.pm.tiensu.model.impl.TEMP_DoiTuongTienSuImpl;
import qldc.pm.tiensu.model.impl.TEMP_DoiTuongTienSuModelImpl;
import qldc.pm.tiensu.service.persistence.TEMP_DoiTuongTienSuPersistence;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the t e m p_ doi tuong tien su service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see TEMP_DoiTuongTienSuPersistence
 * @see TEMP_DoiTuongTienSuUtil
 * @generated
 */
public class TEMP_DoiTuongTienSuPersistenceImpl extends BasePersistenceImpl<TEMP_DoiTuongTienSu>
    implements TEMP_DoiTuongTienSuPersistence {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. Always use {@link TEMP_DoiTuongTienSuUtil} to access the t e m p_ doi tuong tien su persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
     */
    public static final String FINDER_CLASS_NAME_ENTITY = TEMP_DoiTuongTienSuImpl.class.getName();
    public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List1";
    public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List2";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
    public static final FinderPath FINDER_PATH_FETCH_BY_SODINHDANHCANHAN = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class, FINDER_CLASS_NAME_ENTITY,
            "fetchBySoDinhDanhCaNhan", new String[] { String.class.getName() },
            TEMP_DoiTuongTienSuModelImpl.SODINHDANHCANHAN_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_SODINHDANHCANHAN = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "countBySoDinhDanhCaNhan", new String[] { String.class.getName() });
    private static final String _FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1 =
        "temp_DoiTuongTienSu.soDinhDanhCaNhan IS NULL";
    private static final String _FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2 =
        "temp_DoiTuongTienSu.soDinhDanhCaNhan = ?";
    private static final String _FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3 =
        "(temp_DoiTuongTienSu.soDinhDanhCaNhan IS NULL OR temp_DoiTuongTienSu.soDinhDanhCaNhan = '')";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
            new String[] {
                Long.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
        new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
            new String[] { Long.class.getName() },
            TEMP_DoiTuongTienSuModelImpl.USERID_COLUMN_BITMASK |
            TEMP_DoiTuongTienSuModelImpl.CREATEDATE_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
            new String[] { Long.class.getName() });
    private static final String _FINDER_COLUMN_USERID_USERID_2 = "temp_DoiTuongTienSu.userId = ?";
    private static final String _SQL_SELECT_TEMP_DOITUONGTIENSU = "SELECT temp_DoiTuongTienSu FROM TEMP_DoiTuongTienSu temp_DoiTuongTienSu";
    private static final String _SQL_SELECT_TEMP_DOITUONGTIENSU_WHERE = "SELECT temp_DoiTuongTienSu FROM TEMP_DoiTuongTienSu temp_DoiTuongTienSu WHERE ";
    private static final String _SQL_COUNT_TEMP_DOITUONGTIENSU = "SELECT COUNT(temp_DoiTuongTienSu) FROM TEMP_DoiTuongTienSu temp_DoiTuongTienSu";
    private static final String _SQL_COUNT_TEMP_DOITUONGTIENSU_WHERE = "SELECT COUNT(temp_DoiTuongTienSu) FROM TEMP_DoiTuongTienSu temp_DoiTuongTienSu WHERE ";
    private static final String _ORDER_BY_ENTITY_ALIAS = "temp_DoiTuongTienSu.";
    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TEMP_DoiTuongTienSu exists with the primary key ";
    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TEMP_DoiTuongTienSu exists with the key {";
    private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
                PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
    private static Log _log = LogFactoryUtil.getLog(TEMP_DoiTuongTienSuPersistenceImpl.class);
    private static TEMP_DoiTuongTienSu _nullTEMP_DoiTuongTienSu = new TEMP_DoiTuongTienSuImpl() {
            @Override
            public Object clone() {
                return this;
            }

            @Override
            public CacheModel<TEMP_DoiTuongTienSu> toCacheModel() {
                return _nullTEMP_DoiTuongTienSuCacheModel;
            }
        };

    private static CacheModel<TEMP_DoiTuongTienSu> _nullTEMP_DoiTuongTienSuCacheModel =
        new CacheModel<TEMP_DoiTuongTienSu>() {
            @Override
            public TEMP_DoiTuongTienSu toEntityModel() {
                return _nullTEMP_DoiTuongTienSu;
            }
        };

    public TEMP_DoiTuongTienSuPersistenceImpl() {
        setModelClass(TEMP_DoiTuongTienSu.class);
    }

    /**
     * Returns the t e m p_ doi tuong tien su where soDinhDanhCaNhan = &#63; or throws a {@link qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException} if it could not be found.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @return the matching t e m p_ doi tuong tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu findBySoDinhDanhCaNhan(String soDinhDanhCaNhan)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = fetchBySoDinhDanhCaNhan(soDinhDanhCaNhan);

        if (temp_DoiTuongTienSu == null) {
            StringBundler msg = new StringBundler(4);

            msg.append(_NO_SUCH_ENTITY_WITH_KEY);

            msg.append("soDinhDanhCaNhan=");
            msg.append(soDinhDanhCaNhan);

            msg.append(StringPool.CLOSE_CURLY_BRACE);

            if (_log.isWarnEnabled()) {
                _log.warn(msg.toString());
            }

            throw new NoSuchTEMP_DoiTuongTienSuException(msg.toString());
        }

        return temp_DoiTuongTienSu;
    }

    /**
     * Returns the t e m p_ doi tuong tien su where soDinhDanhCaNhan = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @return the matching t e m p_ doi tuong tien su, or <code>null</code> if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu fetchBySoDinhDanhCaNhan(String soDinhDanhCaNhan)
        throws SystemException {
        return fetchBySoDinhDanhCaNhan(soDinhDanhCaNhan, true);
    }

    /**
     * Returns the t e m p_ doi tuong tien su where soDinhDanhCaNhan = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param retrieveFromCache whether to use the finder cache
     * @return the matching t e m p_ doi tuong tien su, or <code>null</code> if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu fetchBySoDinhDanhCaNhan(
        String soDinhDanhCaNhan, boolean retrieveFromCache)
        throws SystemException {
        Object[] finderArgs = new Object[] { soDinhDanhCaNhan };

        Object result = null;

        if (retrieveFromCache) {
            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                    finderArgs, this);
        }

        if (result instanceof TEMP_DoiTuongTienSu) {
            TEMP_DoiTuongTienSu temp_DoiTuongTienSu = (TEMP_DoiTuongTienSu) result;

            if (!Validator.equals(soDinhDanhCaNhan,
                        temp_DoiTuongTienSu.getSoDinhDanhCaNhan())) {
                result = null;
            }
        }

        if (result == null) {
            StringBundler query = new StringBundler(3);

            query.append(_SQL_SELECT_TEMP_DOITUONGTIENSU_WHERE);

            boolean bindSoDinhDanhCaNhan = false;

            if (soDinhDanhCaNhan == null) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1);
            } else if (soDinhDanhCaNhan.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3);
            } else {
                bindSoDinhDanhCaNhan = true;

                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindSoDinhDanhCaNhan) {
                    qPos.add(soDinhDanhCaNhan);
                }

                List<TEMP_DoiTuongTienSu> list = q.list();

                if (list.isEmpty()) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                        finderArgs, list);
                } else {
                    if ((list.size() > 1) && _log.isWarnEnabled()) {
                        _log.warn(
                            "TEMP_DoiTuongTienSuPersistenceImpl.fetchBySoDinhDanhCaNhan(String, boolean) with parameters (" +
                            StringUtil.merge(finderArgs) +
                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                    }

                    TEMP_DoiTuongTienSu temp_DoiTuongTienSu = list.get(0);

                    result = temp_DoiTuongTienSu;

                    cacheResult(temp_DoiTuongTienSu);

                    if ((temp_DoiTuongTienSu.getSoDinhDanhCaNhan() == null) ||
                            !temp_DoiTuongTienSu.getSoDinhDanhCaNhan()
                                                    .equals(soDinhDanhCaNhan)) {
                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                            finderArgs, temp_DoiTuongTienSu);
                    }
                }
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                    finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        if (result instanceof List<?>) {
            return null;
        } else {
            return (TEMP_DoiTuongTienSu) result;
        }
    }

    /**
     * Removes the t e m p_ doi tuong tien su where soDinhDanhCaNhan = &#63; from the database.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @return the t e m p_ doi tuong tien su that was removed
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu removeBySoDinhDanhCaNhan(String soDinhDanhCaNhan)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = findBySoDinhDanhCaNhan(soDinhDanhCaNhan);

        return remove(temp_DoiTuongTienSu);
    }

    /**
     * Returns the number of t e m p_ doi tuong tien sus where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @return the number of matching t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countBySoDinhDanhCaNhan(String soDinhDanhCaNhan)
        throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_SODINHDANHCANHAN;

        Object[] finderArgs = new Object[] { soDinhDanhCaNhan };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_TEMP_DOITUONGTIENSU_WHERE);

            boolean bindSoDinhDanhCaNhan = false;

            if (soDinhDanhCaNhan == null) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1);
            } else if (soDinhDanhCaNhan.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3);
            } else {
                bindSoDinhDanhCaNhan = true;

                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindSoDinhDanhCaNhan) {
                    qPos.add(soDinhDanhCaNhan);
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns all the t e m p_ doi tuong tien sus where userId = &#63;.
     *
     * @param userId the user ID
     * @return the matching t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_DoiTuongTienSu> findByUserId(long userId)
        throws SystemException {
        return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the t e m p_ doi tuong tien sus where userId = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_DoiTuongTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param userId the user ID
     * @param start the lower bound of the range of t e m p_ doi tuong tien sus
     * @param end the upper bound of the range of t e m p_ doi tuong tien sus (not inclusive)
     * @return the range of matching t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_DoiTuongTienSu> findByUserId(long userId, int start,
        int end) throws SystemException {
        return findByUserId(userId, start, end, null);
    }

    /**
     * Returns an ordered range of all the t e m p_ doi tuong tien sus where userId = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_DoiTuongTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param userId the user ID
     * @param start the lower bound of the range of t e m p_ doi tuong tien sus
     * @param end the upper bound of the range of t e m p_ doi tuong tien sus (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_DoiTuongTienSu> findByUserId(long userId, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
            finderArgs = new Object[] { userId };
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
            finderArgs = new Object[] { userId, start, end, orderByComparator };
        }

        List<TEMP_DoiTuongTienSu> list = (List<TEMP_DoiTuongTienSu>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (TEMP_DoiTuongTienSu temp_DoiTuongTienSu : list) {
                if ((userId != temp_DoiTuongTienSu.getUserId())) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(3 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(3);
            }

            query.append(_SQL_SELECT_TEMP_DOITUONGTIENSU_WHERE);

            query.append(_FINDER_COLUMN_USERID_USERID_2);

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(TEMP_DoiTuongTienSuModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(userId);

                if (!pagination) {
                    list = (List<TEMP_DoiTuongTienSu>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<TEMP_DoiTuongTienSu>(list);
                } else {
                    list = (List<TEMP_DoiTuongTienSu>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first t e m p_ doi tuong tien su in the ordered set where userId = &#63;.
     *
     * @param userId the user ID
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching t e m p_ doi tuong tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu findByUserId_First(long userId,
        OrderByComparator orderByComparator)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = fetchByUserId_First(userId,
                orderByComparator);

        if (temp_DoiTuongTienSu != null) {
            return temp_DoiTuongTienSu;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("userId=");
        msg.append(userId);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchTEMP_DoiTuongTienSuException(msg.toString());
    }

    /**
     * Returns the first t e m p_ doi tuong tien su in the ordered set where userId = &#63;.
     *
     * @param userId the user ID
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching t e m p_ doi tuong tien su, or <code>null</code> if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu fetchByUserId_First(long userId,
        OrderByComparator orderByComparator) throws SystemException {
        List<TEMP_DoiTuongTienSu> list = findByUserId(userId, 0, 1,
                orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last t e m p_ doi tuong tien su in the ordered set where userId = &#63;.
     *
     * @param userId the user ID
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching t e m p_ doi tuong tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu findByUserId_Last(long userId,
        OrderByComparator orderByComparator)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = fetchByUserId_Last(userId,
                orderByComparator);

        if (temp_DoiTuongTienSu != null) {
            return temp_DoiTuongTienSu;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("userId=");
        msg.append(userId);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchTEMP_DoiTuongTienSuException(msg.toString());
    }

    /**
     * Returns the last t e m p_ doi tuong tien su in the ordered set where userId = &#63;.
     *
     * @param userId the user ID
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching t e m p_ doi tuong tien su, or <code>null</code> if a matching t e m p_ doi tuong tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu fetchByUserId_Last(long userId,
        OrderByComparator orderByComparator) throws SystemException {
        int count = countByUserId(userId);

        if (count == 0) {
            return null;
        }

        List<TEMP_DoiTuongTienSu> list = findByUserId(userId, count - 1, count,
                orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the t e m p_ doi tuong tien sus before and after the current t e m p_ doi tuong tien su in the ordered set where userId = &#63;.
     *
     * @param doiTuongTienSuId the primary key of the current t e m p_ doi tuong tien su
     * @param userId the user ID
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next t e m p_ doi tuong tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu[] findByUserId_PrevAndNext(
        long doiTuongTienSuId, long userId, OrderByComparator orderByComparator)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = findByPrimaryKey(doiTuongTienSuId);

        Session session = null;

        try {
            session = openSession();

            TEMP_DoiTuongTienSu[] array = new TEMP_DoiTuongTienSuImpl[3];

            array[0] = getByUserId_PrevAndNext(session, temp_DoiTuongTienSu,
                    userId, orderByComparator, true);

            array[1] = temp_DoiTuongTienSu;

            array[2] = getByUserId_PrevAndNext(session, temp_DoiTuongTienSu,
                    userId, orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected TEMP_DoiTuongTienSu getByUserId_PrevAndNext(Session session,
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu, long userId,
        OrderByComparator orderByComparator, boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_TEMP_DOITUONGTIENSU_WHERE);

        query.append(_FINDER_COLUMN_USERID_USERID_2);

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(TEMP_DoiTuongTienSuModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(userId);

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(temp_DoiTuongTienSu);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<TEMP_DoiTuongTienSu> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the t e m p_ doi tuong tien sus where userId = &#63; from the database.
     *
     * @param userId the user ID
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeByUserId(long userId) throws SystemException {
        for (TEMP_DoiTuongTienSu temp_DoiTuongTienSu : findByUserId(userId,
                QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
            remove(temp_DoiTuongTienSu);
        }
    }

    /**
     * Returns the number of t e m p_ doi tuong tien sus where userId = &#63;.
     *
     * @param userId the user ID
     * @return the number of matching t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByUserId(long userId) throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;

        Object[] finderArgs = new Object[] { userId };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_TEMP_DOITUONGTIENSU_WHERE);

            query.append(_FINDER_COLUMN_USERID_USERID_2);

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(userId);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Caches the t e m p_ doi tuong tien su in the entity cache if it is enabled.
     *
     * @param temp_DoiTuongTienSu the t e m p_ doi tuong tien su
     */
    @Override
    public void cacheResult(TEMP_DoiTuongTienSu temp_DoiTuongTienSu) {
        EntityCacheUtil.putResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class, temp_DoiTuongTienSu.getPrimaryKey(),
            temp_DoiTuongTienSu);

        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
            new Object[] { temp_DoiTuongTienSu.getSoDinhDanhCaNhan() },
            temp_DoiTuongTienSu);

        temp_DoiTuongTienSu.resetOriginalValues();
    }

    /**
     * Caches the t e m p_ doi tuong tien sus in the entity cache if it is enabled.
     *
     * @param temp_DoiTuongTienSus the t e m p_ doi tuong tien sus
     */
    @Override
    public void cacheResult(List<TEMP_DoiTuongTienSu> temp_DoiTuongTienSus) {
        for (TEMP_DoiTuongTienSu temp_DoiTuongTienSu : temp_DoiTuongTienSus) {
            if (EntityCacheUtil.getResult(
                        TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
                        TEMP_DoiTuongTienSuImpl.class,
                        temp_DoiTuongTienSu.getPrimaryKey()) == null) {
                cacheResult(temp_DoiTuongTienSu);
            } else {
                temp_DoiTuongTienSu.resetOriginalValues();
            }
        }
    }

    /**
     * Clears the cache for all t e m p_ doi tuong tien sus.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache() {
        if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
            CacheRegistryUtil.clear(TEMP_DoiTuongTienSuImpl.class.getName());
        }

        EntityCacheUtil.clearCache(TEMP_DoiTuongTienSuImpl.class.getName());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    /**
     * Clears the cache for the t e m p_ doi tuong tien su.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache(TEMP_DoiTuongTienSu temp_DoiTuongTienSu) {
        EntityCacheUtil.removeResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class, temp_DoiTuongTienSu.getPrimaryKey());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        clearUniqueFindersCache(temp_DoiTuongTienSu);
    }

    @Override
    public void clearCache(List<TEMP_DoiTuongTienSu> temp_DoiTuongTienSus) {
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        for (TEMP_DoiTuongTienSu temp_DoiTuongTienSu : temp_DoiTuongTienSus) {
            EntityCacheUtil.removeResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
                TEMP_DoiTuongTienSuImpl.class,
                temp_DoiTuongTienSu.getPrimaryKey());

            clearUniqueFindersCache(temp_DoiTuongTienSu);
        }
    }

    protected void cacheUniqueFindersCache(
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu) {
        if (temp_DoiTuongTienSu.isNew()) {
            Object[] args = new Object[] {
                    temp_DoiTuongTienSu.getSoDinhDanhCaNhan()
                };

            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SODINHDANHCANHAN,
                args, Long.valueOf(1));
            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                args, temp_DoiTuongTienSu);
        } else {
            TEMP_DoiTuongTienSuModelImpl temp_DoiTuongTienSuModelImpl = (TEMP_DoiTuongTienSuModelImpl) temp_DoiTuongTienSu;

            if ((temp_DoiTuongTienSuModelImpl.getColumnBitmask() &
                    FINDER_PATH_FETCH_BY_SODINHDANHCANHAN.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        temp_DoiTuongTienSu.getSoDinhDanhCaNhan()
                    };

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SODINHDANHCANHAN,
                    args, Long.valueOf(1));
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                    args, temp_DoiTuongTienSu);
            }
        }
    }

    protected void clearUniqueFindersCache(
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu) {
        TEMP_DoiTuongTienSuModelImpl temp_DoiTuongTienSuModelImpl = (TEMP_DoiTuongTienSuModelImpl) temp_DoiTuongTienSu;

        Object[] args = new Object[] { temp_DoiTuongTienSu.getSoDinhDanhCaNhan() };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SODINHDANHCANHAN, args);
        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN, args);

        if ((temp_DoiTuongTienSuModelImpl.getColumnBitmask() &
                FINDER_PATH_FETCH_BY_SODINHDANHCANHAN.getColumnBitmask()) != 0) {
            args = new Object[] {
                    temp_DoiTuongTienSuModelImpl.getOriginalSoDinhDanhCaNhan()
                };

            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SODINHDANHCANHAN,
                args);
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SODINHDANHCANHAN,
                args);
        }
    }

    /**
     * Creates a new t e m p_ doi tuong tien su with the primary key. Does not add the t e m p_ doi tuong tien su to the database.
     *
     * @param doiTuongTienSuId the primary key for the new t e m p_ doi tuong tien su
     * @return the new t e m p_ doi tuong tien su
     */
    @Override
    public TEMP_DoiTuongTienSu create(long doiTuongTienSuId) {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = new TEMP_DoiTuongTienSuImpl();

        temp_DoiTuongTienSu.setNew(true);
        temp_DoiTuongTienSu.setPrimaryKey(doiTuongTienSuId);

        return temp_DoiTuongTienSu;
    }

    /**
     * Removes the t e m p_ doi tuong tien su with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param doiTuongTienSuId the primary key of the t e m p_ doi tuong tien su
     * @return the t e m p_ doi tuong tien su that was removed
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu remove(long doiTuongTienSuId)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        return remove((Serializable) doiTuongTienSuId);
    }

    /**
     * Removes the t e m p_ doi tuong tien su with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param primaryKey the primary key of the t e m p_ doi tuong tien su
     * @return the t e m p_ doi tuong tien su that was removed
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu remove(Serializable primaryKey)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        Session session = null;

        try {
            session = openSession();

            TEMP_DoiTuongTienSu temp_DoiTuongTienSu = (TEMP_DoiTuongTienSu) session.get(TEMP_DoiTuongTienSuImpl.class,
                    primaryKey);

            if (temp_DoiTuongTienSu == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
                }

                throw new NoSuchTEMP_DoiTuongTienSuException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                    primaryKey);
            }

            return remove(temp_DoiTuongTienSu);
        } catch (NoSuchTEMP_DoiTuongTienSuException nsee) {
            throw nsee;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    @Override
    protected TEMP_DoiTuongTienSu removeImpl(
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu) throws SystemException {
        temp_DoiTuongTienSu = toUnwrappedModel(temp_DoiTuongTienSu);

        Session session = null;

        try {
            session = openSession();

            if (!session.contains(temp_DoiTuongTienSu)) {
                temp_DoiTuongTienSu = (TEMP_DoiTuongTienSu) session.get(TEMP_DoiTuongTienSuImpl.class,
                        temp_DoiTuongTienSu.getPrimaryKeyObj());
            }

            if (temp_DoiTuongTienSu != null) {
                session.delete(temp_DoiTuongTienSu);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        if (temp_DoiTuongTienSu != null) {
            clearCache(temp_DoiTuongTienSu);
        }

        return temp_DoiTuongTienSu;
    }

    @Override
    public TEMP_DoiTuongTienSu updateImpl(
        qldc.pm.tiensu.model.TEMP_DoiTuongTienSu temp_DoiTuongTienSu)
        throws SystemException {
        temp_DoiTuongTienSu = toUnwrappedModel(temp_DoiTuongTienSu);

        boolean isNew = temp_DoiTuongTienSu.isNew();

        TEMP_DoiTuongTienSuModelImpl temp_DoiTuongTienSuModelImpl = (TEMP_DoiTuongTienSuModelImpl) temp_DoiTuongTienSu;

        Session session = null;

        try {
            session = openSession();

            if (temp_DoiTuongTienSu.isNew()) {
                session.save(temp_DoiTuongTienSu);

                temp_DoiTuongTienSu.setNew(false);
            } else {
                session.merge(temp_DoiTuongTienSu);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

        if (isNew || !TEMP_DoiTuongTienSuModelImpl.COLUMN_BITMASK_ENABLED) {
            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
        }
        else {
            if ((temp_DoiTuongTienSuModelImpl.getColumnBitmask() &
                    FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        temp_DoiTuongTienSuModelImpl.getOriginalUserId()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
                    args);

                args = new Object[] { temp_DoiTuongTienSuModelImpl.getUserId() };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
                    args);
            }
        }

        EntityCacheUtil.putResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_DoiTuongTienSuImpl.class, temp_DoiTuongTienSu.getPrimaryKey(),
            temp_DoiTuongTienSu);

        clearUniqueFindersCache(temp_DoiTuongTienSu);
        cacheUniqueFindersCache(temp_DoiTuongTienSu);

        return temp_DoiTuongTienSu;
    }

    protected TEMP_DoiTuongTienSu toUnwrappedModel(
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu) {
        if (temp_DoiTuongTienSu instanceof TEMP_DoiTuongTienSuImpl) {
            return temp_DoiTuongTienSu;
        }

        TEMP_DoiTuongTienSuImpl temp_DoiTuongTienSuImpl = new TEMP_DoiTuongTienSuImpl();

        temp_DoiTuongTienSuImpl.setNew(temp_DoiTuongTienSu.isNew());
        temp_DoiTuongTienSuImpl.setPrimaryKey(temp_DoiTuongTienSu.getPrimaryKey());

        temp_DoiTuongTienSuImpl.setDoiTuongTienSuId(temp_DoiTuongTienSu.getDoiTuongTienSuId());
        temp_DoiTuongTienSuImpl.setUserId(temp_DoiTuongTienSu.getUserId());
        temp_DoiTuongTienSuImpl.setUserName(temp_DoiTuongTienSu.getUserName());
        temp_DoiTuongTienSuImpl.setCreateDate(temp_DoiTuongTienSu.getCreateDate());
        temp_DoiTuongTienSuImpl.setModifiedDate(temp_DoiTuongTienSu.getModifiedDate());
        temp_DoiTuongTienSuImpl.setSoDinhDanhCaNhan(temp_DoiTuongTienSu.getSoDinhDanhCaNhan());
        temp_DoiTuongTienSuImpl.setXoaAnTich(temp_DoiTuongTienSu.getXoaAnTich());
        temp_DoiTuongTienSuImpl.setUndoRedo(temp_DoiTuongTienSu.getUndoRedo());
        temp_DoiTuongTienSuImpl.setThaoTac(temp_DoiTuongTienSu.getThaoTac());
        temp_DoiTuongTienSuImpl.setMainDoiTuongTienSuId(temp_DoiTuongTienSu.getMainDoiTuongTienSuId());

        return temp_DoiTuongTienSuImpl;
    }

    /**
     * Returns the t e m p_ doi tuong tien su with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
     *
     * @param primaryKey the primary key of the t e m p_ doi tuong tien su
     * @return the t e m p_ doi tuong tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu findByPrimaryKey(Serializable primaryKey)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = fetchByPrimaryKey(primaryKey);

        if (temp_DoiTuongTienSu == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }

            throw new NoSuchTEMP_DoiTuongTienSuException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                primaryKey);
        }

        return temp_DoiTuongTienSu;
    }

    /**
     * Returns the t e m p_ doi tuong tien su with the primary key or throws a {@link qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException} if it could not be found.
     *
     * @param doiTuongTienSuId the primary key of the t e m p_ doi tuong tien su
     * @return the t e m p_ doi tuong tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_DoiTuongTienSuException if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu findByPrimaryKey(long doiTuongTienSuId)
        throws NoSuchTEMP_DoiTuongTienSuException, SystemException {
        return findByPrimaryKey((Serializable) doiTuongTienSuId);
    }

    /**
     * Returns the t e m p_ doi tuong tien su with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param primaryKey the primary key of the t e m p_ doi tuong tien su
     * @return the t e m p_ doi tuong tien su, or <code>null</code> if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu fetchByPrimaryKey(Serializable primaryKey)
        throws SystemException {
        TEMP_DoiTuongTienSu temp_DoiTuongTienSu = (TEMP_DoiTuongTienSu) EntityCacheUtil.getResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
                TEMP_DoiTuongTienSuImpl.class, primaryKey);

        if (temp_DoiTuongTienSu == _nullTEMP_DoiTuongTienSu) {
            return null;
        }

        if (temp_DoiTuongTienSu == null) {
            Session session = null;

            try {
                session = openSession();

                temp_DoiTuongTienSu = (TEMP_DoiTuongTienSu) session.get(TEMP_DoiTuongTienSuImpl.class,
                        primaryKey);

                if (temp_DoiTuongTienSu != null) {
                    cacheResult(temp_DoiTuongTienSu);
                } else {
                    EntityCacheUtil.putResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
                        TEMP_DoiTuongTienSuImpl.class, primaryKey,
                        _nullTEMP_DoiTuongTienSu);
                }
            } catch (Exception e) {
                EntityCacheUtil.removeResult(TEMP_DoiTuongTienSuModelImpl.ENTITY_CACHE_ENABLED,
                    TEMP_DoiTuongTienSuImpl.class, primaryKey);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return temp_DoiTuongTienSu;
    }

    /**
     * Returns the t e m p_ doi tuong tien su with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param doiTuongTienSuId the primary key of the t e m p_ doi tuong tien su
     * @return the t e m p_ doi tuong tien su, or <code>null</code> if a t e m p_ doi tuong tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_DoiTuongTienSu fetchByPrimaryKey(long doiTuongTienSuId)
        throws SystemException {
        return fetchByPrimaryKey((Serializable) doiTuongTienSuId);
    }

    /**
     * Returns all the t e m p_ doi tuong tien sus.
     *
     * @return the t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_DoiTuongTienSu> findAll() throws SystemException {
        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the t e m p_ doi tuong tien sus.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_DoiTuongTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of t e m p_ doi tuong tien sus
     * @param end the upper bound of the range of t e m p_ doi tuong tien sus (not inclusive)
     * @return the range of t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_DoiTuongTienSu> findAll(int start, int end)
        throws SystemException {
        return findAll(start, end, null);
    }

    /**
     * Returns an ordered range of all the t e m p_ doi tuong tien sus.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_DoiTuongTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of t e m p_ doi tuong tien sus
     * @param end the upper bound of the range of t e m p_ doi tuong tien sus (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_DoiTuongTienSu> findAll(int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
            finderArgs = FINDER_ARGS_EMPTY;
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
            finderArgs = new Object[] { start, end, orderByComparator };
        }

        List<TEMP_DoiTuongTienSu> list = (List<TEMP_DoiTuongTienSu>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if (list == null) {
            StringBundler query = null;
            String sql = null;

            if (orderByComparator != null) {
                query = new StringBundler(2 +
                        (orderByComparator.getOrderByFields().length * 3));

                query.append(_SQL_SELECT_TEMP_DOITUONGTIENSU);

                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);

                sql = query.toString();
            } else {
                sql = _SQL_SELECT_TEMP_DOITUONGTIENSU;

                if (pagination) {
                    sql = sql.concat(TEMP_DoiTuongTienSuModelImpl.ORDER_BY_JPQL);
                }
            }

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                if (!pagination) {
                    list = (List<TEMP_DoiTuongTienSu>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<TEMP_DoiTuongTienSu>(list);
                } else {
                    list = (List<TEMP_DoiTuongTienSu>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Removes all the t e m p_ doi tuong tien sus from the database.
     *
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeAll() throws SystemException {
        for (TEMP_DoiTuongTienSu temp_DoiTuongTienSu : findAll()) {
            remove(temp_DoiTuongTienSu);
        }
    }

    /**
     * Returns the number of t e m p_ doi tuong tien sus.
     *
     * @return the number of t e m p_ doi tuong tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countAll() throws SystemException {
        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
                FINDER_ARGS_EMPTY, this);

        if (count == null) {
            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(_SQL_COUNT_TEMP_DOITUONGTIENSU);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Initializes the t e m p_ doi tuong tien su persistence.
     */
    public void afterPropertiesSet() {
        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
                    com.liferay.util.service.ServiceProps.get(
                        "value.object.listener.qldc.pm.tiensu.model.TEMP_DoiTuongTienSu")));

        if (listenerClassNames.length > 0) {
            try {
                List<ModelListener<TEMP_DoiTuongTienSu>> listenersList = new ArrayList<ModelListener<TEMP_DoiTuongTienSu>>();

                for (String listenerClassName : listenerClassNames) {
                    listenersList.add((ModelListener<TEMP_DoiTuongTienSu>) InstanceFactory.newInstance(
                            getClassLoader(), listenerClassName));
                }

                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
            } catch (Exception e) {
                _log.error(e);
            }
        }
    }

    public void destroy() {
        EntityCacheUtil.removeCache(TEMP_DoiTuongTienSuImpl.class.getName());
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }
}
